﻿import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'change_password_logic.dart';

/// 修改密码页面
class ChangePasswordView extends GetView<ChangePasswordLogic> {
  const ChangePasswordView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFF282528),
      appBar: AppBar(
        backgroundColor: const Color(0xFF282528),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '修改密码',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24.w),
        child: Column(
          children: [
            // 旧密码
            Container(
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
              decoration: BoxDecoration(
                color: const Color(0xFF2A2A2A),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '旧密码',
                    style: TextStyle(
                      color: const Color(0xFF666666),
                      fontSize: 14.sp,
                    ),
                  ),
                  SizedBox(height: 8.h),
                  Obx(() => TextField(
                        controller: controller.oldPasswordController,
                        obscureText: !controller.showOldPassword.value,
                        style: const TextStyle(color: Colors.white, fontSize: 16),
                        decoration: InputDecoration(
                          hintText: '请输入旧密码',
                          hintStyle: const TextStyle(color: Color(0xFF666666)),
                          border: InputBorder.none,
                          suffixIcon: IconButton(
                            icon: Icon(
                              controller.showOldPassword.value
                                  ? Icons.visibility
                                  : Icons.visibility_off,
                              color: const Color(0xFF666666),
                            ),
                            onPressed: () => controller.showOldPassword.toggle(),
                          ),
                        ),
                      )),
                ],
              ),
            ),
            SizedBox(height: 16.h),
            // 新密码
            Container(
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
              decoration: BoxDecoration(
                color: const Color(0xFF2A2A2A),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '新密码',
                    style: TextStyle(
                      color: const Color(0xFF666666),
                      fontSize: 14.sp,
                    ),
                  ),
                  SizedBox(height: 8.h),
                  Obx(() => TextField(
                        controller: controller.newPasswordController,
                        obscureText: !controller.showNewPassword.value,
                        style: const TextStyle(color: Colors.white, fontSize: 16),
                        decoration: InputDecoration(
                          hintText: '请输入新密码（6-20位）',
                          hintStyle: const TextStyle(color: Color(0xFF666666)),
                          border: InputBorder.none,
                          suffixIcon: IconButton(
                            icon: Icon(
                              controller.showNewPassword.value
                                  ? Icons.visibility
                                  : Icons.visibility_off,
                              color: const Color(0xFF666666),
                            ),
                            onPressed: () => controller.showNewPassword.toggle(),
                          ),
                        ),
                      )),
                ],
              ),
            ),
            SizedBox(height: 16.h),
            // 确认新密码
            Container(
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
              decoration: BoxDecoration(
                color: const Color(0xFF2A2A2A),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '确认新密码',
                    style: TextStyle(
                      color: const Color(0xFF666666),
                      fontSize: 14.sp,
                    ),
                  ),
                  SizedBox(height: 8.h),
                  Obx(() => TextField(
                        controller: controller.confirmPasswordController,
                        obscureText: !controller.showConfirmPassword.value,
                        style: const TextStyle(color: Colors.white, fontSize: 16),
                        decoration: InputDecoration(
                          hintText: '请再次输入新密码',
                          hintStyle: const TextStyle(color: Color(0xFF666666)),
                          border: InputBorder.none,
                          suffixIcon: IconButton(
                            icon: Icon(
                              controller.showConfirmPassword.value
                                  ? Icons.visibility
                                  : Icons.visibility_off,
                              color: const Color(0xFF666666),
                            ),
                            onPressed: () => controller.showConfirmPassword.toggle(),
                          ),
                        ),
                      )),
                ],
              ),
            ),
            SizedBox(height: 40.h),
            // 确认按钮
            Container(
              width: double.infinity,
              height: 50.h,
              child: ElevatedButton(
                onPressed: () => controller.changePassword(),
                style: ElevatedButton.styleFrom(
                  backgroundColor: const Color(0xFF007AFF),
                  foregroundColor: Colors.white,
                  elevation: 0,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(25.r),
                  ),
                ),
                child: Text(
                  '确认修改',
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
